
<template>
    <h1 style="text-align: center;">分销海报</h1>
    <div>
        <van-image
        width="100%"
        height="75%"
        :src="poster"
        />

    </div>

    <div class="box">
        <van-cell-group inset>
        <van-field
            v-model="list"
            id="url"
            readonly
            center
            clearable
            size="large"
            placeholder=""

        >
            <template #button>
            <van-button size="small" type="primary" @click="Copy(list)">点击复制</van-button>
            </template>
        </van-field>
        </van-cell-group>
    </div>
    <Tabbar />
</template>

<script setup>
    const {proxy} = getCurrentInstance()

    let business = proxy.$business.value
    let list = ref([])

    let poster = ref()
    
    onMounted(() => {
        GetCode()
    })

    const GetCode = async () => {

        //前端获取域名
        var name = window.location.href
        // console.log(name)
        var params = {
            busid: business.id,
            name
        }
        // console.log(DomainName)
        var result = await proxy.$POST({
            url: 'sale/code',
            params,
        })
        console.log(result)

        if(result.code == 0)
        {
            proxy.$error(result.msg)
            return false
        }

        poster.value = result.data.poster
        // console.log(poster.value)
        // return false
        list.value = result.data.link
    }

    const Copy = async (list) => {
        // console.log(list)

        navigator.clipboard.writeText(list).then(() => {
        // 可以添加用户提示复制成功
        proxy.$success('内容已复制');
      }).catch(err => {
        console.error('复制失败', err);
      });
        
    }


</script>

<style scoped>
    .van-field{
        font-size: 20px
    }
    .van-button{
        font-size: 18px
    }
    @import url('/assets/css/SaleMoney.css');
</style>